package com.betty.cscams.controller;

import com.betty.cscams.common.http.HttpResult;
import com.betty.cscams.common.page.PageRequest;
import com.betty.cscams.constant.SysConstants;
import com.betty.cscams.entity.BusSports;
import com.betty.cscams.entity.BusTerm;
import com.betty.cscams.entity.SysFile;
import com.betty.cscams.service.BusSportsService;
import com.betty.cscams.service.BusTermService;
import com.betty.cscams.service.SysFileService;
import com.betty.cscams.vo.ScoreQueryBean;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * ---------------------------
 *  (BusSportsController)         
 * ---------------------------
 * 时间：  2022-03-12 17:12:38
 * ---------------------------
 */
@RestController
@RequestMapping("sysFile")
public class SysFileController {

	@Autowired
	private SysFileService fileService;

	@Autowired
	private SysFileService sysFileService;

	/**
	 * 保存
	 * @param file
	 * @param busiId
	 * @param type
	 * @return
	 */	
	@PostMapping(value="/upload")
	public HttpResult upload(MultipartFile file, Long busiId,Integer type) throws Exception {
		return HttpResult.ok(sysFileService.save(file,busiId,type));
	}

    /**
     * 删除
     * @param records
     * @return
     */
	@PostMapping(value="/remove")
	public HttpResult remove(@RequestBody SysFile  records) {
		return HttpResult.ok(sysFileService.delete(records));
	}

    /**
     * 基础列表查询
     * @param busiId
	 * @param type
     * @return
     */    
	@GetMapping(value="/findList")
	public HttpResult findList(Long busiId,Integer type) {
		return HttpResult.ok(sysFileService.findList(busiId,type));
	}

	@PostMapping(value="/download")
	public HttpResult download(@RequestBody SysFile  sysFile, HttpServletResponse response, HttpServletRequest request) throws Exception {
		sysFileService.download(sysFile.getPath(),sysFile.getName(),request,response);
		return HttpResult.ok();
	}

	/**
	 * 保存
	 * @param file
	 * @return
	 */
	@PostMapping(value="/uploadImg")
	public HttpResult uploadImg(MultipartFile file) throws Exception {
		return HttpResult.ok(sysFileService.uploadImg(file));
	}

}
